{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">用户管理</h1>
    <a href="{{ url_for('auth.create_user') }}" class="btn btn-primary">
        <i class="bi bi-plus-circle me-1"></i>添加用户
    </a>
</div>

<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>角色</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
            <tr>
                <td>{{ user.id }}</td>
                <td>{{ user.username }}</td>
                <td>
                    {% if user.role == 'admin' %}
                        <span class="badge bg-danger">管理员</span>
                    {% else %}
                        <span class="badge bg-secondary">普通用户</span>
                    {% endif %}
                </td>
                <td>{{ user.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                <td>
                    {% if user.id != current_user.id %}
                    <form method="POST" action="{{ url_for('auth.delete_user', user_id=user.id) }}" class="d-inline" onsubmit="return confirm('确定要删除此用户吗？')">
                        <button type="submit" class="btn btn-sm btn-outline-danger">删除</button>
                    </form>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}